<!-- <template>

</template>
<script>
import { RecommendUserService,RecommendGoodsService } from "./like";
console.log(JSON.parse(localStorage.getItem("user")) )
let data=[{userId: 1, goodsId: 11},{userId:2,goodsId:222}]
const recommendUserService = new RecommendUserService(data,userId,n)
    const result = recommendUserService.start() 
 export default {
    created:function(){

    },
    data(){
          
         return {
             name:"hh"
         }
    }
  
 }
</script> -->
<template>
    <div>
        <userNav></userNav>
        <div  class="banner">
  <swiperDemo></swiperDemo>
</div>
        
  
    <div  class="content">
      <router-link  v-for="item in searchs"   :to="{path:'/video',query:{title:item.title,context:item.context,id:item.id,imgSrc:item.imgSrc,videoSrc:item.videoSrc}}"  :key="item.id" class="box">
            <!-- <myContent :title="item.title" :context="item.context"></myContent> -->
            <foundation :title="item.title" :context="item.context" :imgSrc="'http://192.168.134.47:8889'+'/'+item.imgSrc+'.jpg'"></foundation>
            </router-link>   
     </div>
    


    </div>
 
  


</template>

<script>
import userNav from "./userNav"
import swiperDemo from "../components/swiperDemo.vue"
import  foundation from "../components/foundation.vue"
import { RecommendUserService,RecommendGoodsService } from "./like";
// console.log(JSON.parse(localStorage.getItem("user")) )
let data=JSON.parse(localStorage.getItem("rateDate"))
let userId=JSON.parse(localStorage.getItem("user"))[0].id
const recommendUserService = new RecommendUserService(data,userId,10)
    const result = recommendUserService.start() 
    const recommendGoodsService = new RecommendGoodsService(data,userId,10)
    const results = recommendGoodsService.start()
    const recommendGoodsServices = new RecommendGoodsService(data,userId,10)
    const resultss = recommendGoodsServices.getGoodsGrade(result,results)     
          localStorage.setItem("like",JSON.stringify(resultss))
          console.log(resultss)

         
export default{
    components:{
        userNav,
        swiperDemo,
        foundation
      
     
         
    },
      data(){
         return {
            dataArr:[
         
         ],
         arr:[]
        
        }
         
      },
      beforeCreate(){
         this.$axios.get(this.$host+"/getRateData").then(resp=>{
                     
                        //  console.log(resp.data)
                     this.arr=resp.data
                    //  console.log(this.arr)
                    this.getArr(this.arr)
         })
         
      },
      created()
    {
    //   this.$axios.get(this.$host+"/like").then(res=>{
    //         this.dataArr=res.data
    //         // console.log(res.data)
    //   })
         this.$axios({
               method:"get",
               url:this.$host+"/like",
               params:{
                goodsId:JSON.parse(localStorage.getItem("like"))
               }
         }).then(resp=>{
                   this.dataArr=resp.data
                // console.log(resp.data)
         })
    },
   
    methods:{
          getArr(arr){
            let newArrs=[]
            // let useridArr=[]
        arr.forEach(item=>{
           let newObj={
             userId:item.userId,
             goodsId:item.MovieId,
             values:item.rateValue
           }
        //    useridArr.push()
           newArrs.push(newObj)
        })
           
        // console.log(newArrs)
        // console.log(useridArr)
        localStorage.setItem("rateDate", JSON.stringify(newArrs))
         this.$store.dispatch("algorithm",newArrs)


          }
    },
    computed:{

         searchs(){
             if(this.inputValue!=""){
               return this.dataArr.filter(value=>{
                   return value.title.indexOf(this.$store.state.movie.searchValue)!==-1 
               })
              

             }else{
               return this.dataArr
             }

              
          
            //  if(this.inputValue==""){
            //      return this.dataArr
            //  }
            // return this.dataArr.filter((value)=>{
            //      return value.title.indexOf(this.$store.state.movie)!==-1
                
            // }) 
         }
          
    }

     
 
     
}

</script>
<style scoped>
  a{
        text-decoration: none;
        color: blue;
    }
    
    .box{
      margin-left:30px;
      margin-top: 80px;
    }
    .banner{
       margin-top: 60px;
    }
    
    .content{
       display: flex;
       flex-wrap: wrap;
       justify-content: space-around;
       margin-top: 50px;
    
    }
    
    
    </style>